local keys = cmsgpack.unpack(ARGV[1]);
local values = cmsgpack.unpack(ARGV[2]);
local valuesSize = table.getn(values);
for i=1,valuesSize do
  local tmpValues = values[i];
  local tmpValuesSize = table.getn(tmpValues);
  for j=1,tmpValuesSize do
    local tmpKey = keys[j];
    local tmpValue = tmpValues[j];
    redis.call("HSET",KEYS[i+1],tmpKey,tmpValue);
  end
  redis.call("ZADD",KEYS[1],0,KEYS[i+1]);
end
local keyss = table.getn(KEYS);
local conditionKey = KEYS[keyss];
if (conditionKey~="") then
  redis.call("ZADD",conditionKey,0,KEYS[1]);
end
--[[ 
local listAllSize = redis.call("EXISTS",KEYS[2]);
if(listAllSize>0) then
  redis.call("ZADD",KEYS[2],0,KEYS[1]);
end
]]